package whu.o2o;

import java.io.Serializable;

import whu.o2o.View.LoadDialog;
import whu.o2o.util.ConstantData;
import whu.o2o.util.ParseXml;
import whu.o2o.vo.MessageVO;
import whu.o2o.vo.PersonVO;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RatingBar;
import android.widget.TextView;

import whu.o2o.R;




public class GuideCardActivity extends BaseActivity implements OnClickListener {
	private TextView mName;
	private TextView mSexAndAge;
	private TextView mAge;
	private TextView mSex;
	private TextView mLevel;
	private PersonVO mGuideVO;
	private boolean flag;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_guide_card);
		getIntentData();
		initObject();
		initView();
		initListener();
		//initData();
	}

	@Override
	public void onClick(View v) {
		Intent intent;

		switch (v.getId()) {

		case R.id.comment:
			
			break;

		case R.id.route:
			intent = new Intent(mContext, RouteListActivity.class);
			intent.putExtra("title","我的订单");
			intent.putExtra("url", String.format(ConstantData.Url.GET_GUIDE_ROUTE, mGuideVO.getId()));
			startActivity(intent);
			break;

		case R.id.diary:
			intent = new Intent(mContext, DiaryListActivity.class);
			intent.putExtra("title","我的商品列表");
			intent.putExtra("url", String.format(ConstantData.Url.GET_GUIDE_DIARY, mGuideVO.getId()));
			intent.putExtra("flag", flag);
			startActivity(intent);
			break;

		case R.id.studio:
			intent = new Intent(mContext, MystudioActivity.class);
			intent.putExtra("title", "我的浏览轨迹");
			intent.putExtra("guideId", mGuideVO.getId());
			intent.putExtra("flag", flag);
			startActivity(intent);
			break;
		}

	}

	@Override
	protected void parseData(final String xml) {
		Log.d("aaa", xml);
		mApplication.getThreadPool().execute(new Runnable() {

			@Override
			public void run() {
				ParseXml.getInstance().parseGuideCardXml(xml, mGuideVO);
				mHttpHandler.sendEmptyMessage(ConstantData.Data.PARSE_XML_MSG_CODE);
			}
		});

	}

	@Override
	protected void setData() {
		setSimpleData();
		setDetailData();

	}

	private void getIntentData() {
		Intent intent = getIntent();
		if (intent != null) {
			Serializable serializable = intent.getSerializableExtra("card");
			if (serializable != null) {
				mGuideVO = (PersonVO) serializable;
			}
		}
	}

	private void initObject() {
		if (mGuideVO == null) {
			mGuideVO = new PersonVO();
		}

	}

	private void initView() {
		mName = (TextView) findViewById(R.id.name);
		mSex = (TextView) findViewById(R.id.sex);
		mAge = (TextView) findViewById(R.id.age);
		mLevel = (TextView) findViewById(R.id.level);
	}

	private void initListener() {
		backBtnClick();
		findViewById(R.id.route).setOnClickListener(this);
		findViewById(R.id.diary).setOnClickListener(this);
		findViewById(R.id.studio).setOnClickListener(this);
		findViewById(R.id.comment).setOnClickListener(this);
	}

	private void initData() {
		setSimpleData();
		requestData();
		if(mGuideVO.getId()==mApplication.getUserId())
			flag = false;
		else
		    flag = true;
	}     

	private void requestData() {

	}

	private void setSimpleData() {
	}

	private void setDetailData() {
		setTextViewText(R.id.comment, new StringBuffer().append(mGuideVO.getCommentCount()).append("评论"));
		setTextViewText(R.id.good, new StringBuffer().append(mGuideVO.getGoodCount()).append("赞"));
		setTextViewText(R.id.phone, mGuideVO.getPhone());
		setTextViewText(R.id.agency, mGuideVO.getAgency());

		((RatingBar) findViewById(R.id.looks)).setRating(mGuideVO.getLooks());
		((RatingBar) findViewById(R.id.humor)).setRating(mGuideVO.getHumor());
		((RatingBar) findViewById(R.id.profession)).setRating(mGuideVO.getProfession());
		((RatingBar) findViewById(R.id.patience)).setRating(mGuideVO.getPatience());
		((RatingBar) findViewById(R.id.erudite)).setRating(mGuideVO.getErudite());
	}
}
